<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Constants\CtrlRoomListeningContentConstants;
use App\CustHub\Request\CtrlRoomRequest;
use App\CustHub\Service\ChCtrlRoomSchemeService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ResponseInterface;

/**
 * 中控群
 */
#[Controller('ch/ctrl/room'),VerifySignature,ApiAuth]
class CtrlRoomSchemeController extends BaseController
{
    #[Inject]
    protected ChCtrlRoomSchemeService $service;

    /**
     * 方案列表
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('list')]
    public function list(): ResponseInterface
    {
        return $this->success($this->service->getSchemePageList($this->request->all()));
    }

    /**
     * 保存方案
     * @param CtrlRoomRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function save(CtrlRoomRequest $request): ResponseInterface
    {
        return $this->service->saveScheme($request->all()) ? $this->success() : $this->error();
    }

    /**
     * @param CtrlRoomRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('getInfo')]
    public function getInfo(CtrlRoomRequest $request)
    {
        return $this->success($this->service->getInfo($request->all()));
    }

    /**
     * 更新方案
     * @param CtrlRoomRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('update')]
    public function update(CtrlRoomRequest $request): ResponseInterface
    {
        return $this->service->updateScheme($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除方案
     * @param CtrlRoomRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('delete')]
    public function delete(CtrlRoomRequest $request): ResponseInterface
    {
        return $this->service->deleteScheme($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 修改备注
     * @param CtrlRoomRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('editRemark')]
    public function editRemark(CtrlRoomRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->editRemark($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 状态切换
     * @param CtrlRoomRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('changeStatus')]
    public function changeStatus(CtrlRoomRequest $request): ResponseInterface
    {
        return $this->service->changeStatus($request->input('id'),$request->input('status'),'status') ? $this->success() : $this->error();
    }

    /**
     * 复制
     * @param CtrlRoomRequest $request
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('copy')]
    public function copy(CtrlRoomRequest $request): ResponseInterface
    {
        return $this->service->copy($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 保存中控群全局过滤规则
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('saveRules')]
    public function saveRule(): ResponseInterface
    {
        return $this->service->saveRule($this->request->all()) ? $this->success() : $this->error();
    }

    /**
     * 获取中控群全局过滤规则
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('getRuleInfo')]
    public function getRuleInfo(): ResponseInterface
    {
        return  $this->success($this->service->getRuleInfo($this->request->all()));
    }


    /**
     * 获取监听内容
     * @return ResponseInterface
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface
     */
    #[PostMapping('getListeningContent')]
    public function getListeningContent(): ResponseInterface
    {
        return $this->success(CtrlRoomListeningContentConstants::getOptions());
    }
}